#include "headfiles.h"

NODE * reverseKNode(NODE *head, int k) {
    if (head == NULL) {
        return NULL;
    }

    int i;
    NODE *n = head;
    for (i = 0; i < k; i++) {
        if (n) {
            n = n->next;
        }
        else {
            break;
        }
    }

    // number of nodes is less than k, 
    // no reverse
    if (i < k) {
        return head;
    }

    n = head;
    for (i = 0; i < k; i++) {
        NODE *next = n->next;
        n->next = head;
        head = n;
        n = next;
    }

    return head;
}


